package clientserver;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Quynh
 */

import java.io.*;
import java.net.*;

class TCPClient {
   public static void main(String argv[]) throws Exception
   {
      String sentence;
      String modifiedSentence;
      Integer portno;

      if (argv.length != 2) {
         System.out.println("Usage:  TCPClient <host name> <port number>");
	 System.exit(1);
      }

      portno = Integer.parseInt(argv[1]);
      BufferedReader inFromUser = new BufferedReader(
		      new InputStreamReader(System.in));
      Socket clientSocket = new Socket(argv[0], portno);
      System.out.println("Java client: Opening TCP connection to " + argv[0] +
		 " on port " + argv[1] + "..." );
      DataOutputStream outToServer = new DataOutputStream(
		      clientSocket.getOutputStream());
      BufferedReader inFromServer =
	      new BufferedReader(new InputStreamReader(
		      clientSocket.getInputStream()));
      sentence = inFromUser.readLine();
      outToServer.writeBytes(sentence + '\n');
      modifiedSentence = inFromServer.readLine();
      System.out.println("FROM SERVER: " + modifiedSentence);
      clientSocket.close();
   }
}
